//--------------------小黑记事本处理函数-----------------------

//导入数据库
const db = require('../db/index')

//获取小黑记事本列表的处理函数
exports.getXhList = (req, res) => {
  const sql = "select * from api_xh where creator = ? and is_delete = 0"
  db.query(sql, [req.query.creator], (err, results) => {
    if (err) return res.send(err)
    res.send({
      status: 0,
      message: "查询成功",
      data: results
    })
  })
}

//小黑记事本新增列表的处理函数
exports.addXhList = (req, res) => {
  const sql = 'insert into api_xh set ?'
  db.query(sql, req.body, (err, result) => {
    if (err) return res.cc(err)
    if (result.affectedRows !== 1) return res.cc('新增列表失败')
    return res.cc('新增列表成功', 0)
  })

}

//小黑记事本删除列表的处理函数
exports.deleteList = (req, res) => {
  const sql = 'update api_xh set is_delete = 1 where id = ?'
  db.query(sql, req.params.id, (err, result) => {
    if (err) return res.cc(err)
    if (result.affectedRows !== 1) return res.cc("删除列表失败")
    res.cc("删除列表成功", 0)
  })
}